package com.yyx.lgb.manager.controller;

import com.github.pagehelper.PageInfo;
import com.yyx.lgb.common.log.annotation.Log;
import com.yyx.lgb.common.log.enums.OperatorType;
import com.yyx.lgb.manager.service.BrandService;
import com.yyx.lgb.model.entity.product.Brand;
import com.yyx.lgb.model.vo.common.Result;
import com.yyx.lgb.model.vo.common.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: BrandController
 * Package: com.yyx.lgb.manager.controller
 * Description:
 *
 * @Author: yyx
 * @Create: 2025/8/6 - 15:31
 */
@RestController
@RequestMapping(value="/admin/product/brand")
public class BrandController {
    @Autowired
    private BrandService brandService;

    @Log(title = "品牌列表",businessType = 0,operatorType = OperatorType.MANAGE)
    @GetMapping("/{page}/{limit}")
    public Result<PageInfo<Brand>> findByPage(@PathVariable Integer page,@PathVariable Integer limit){
        PageInfo<Brand> pageInfo=brandService.findByPage(page,limit);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }
    @PostMapping("/save")
    public Result save(@RequestBody Brand brand){
        brandService.save(brand);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @PutMapping("updateById")
    public Result updateById(@RequestBody Brand brand){
        brandService.updateById(brand);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Long id){
        brandService.deleteById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/findAll")
    public Result findAll() {
        List<Brand> list = brandService.findAll();
        return Result.build(list , ResultCodeEnum.SUCCESS) ;
    }


}
